
%inline
%{
#include <string>
#include "google/protobuf/io/coded_stream.h"
%}



%include "typemaps.i"
%include "protobuf_typemaps.i"
%include "zero_copy_stream.i"



namespace google
{
   namespace protobuf
   {
       namespace io
       {

            %typemap(argout) ::google::protobuf::uint32 *OutValue
            {
                
                PyObject *o, *o2, *o3;
            
                o = PyLong_FromUnsignedLong(*$1);
                
                if((!$result) || ($result == Py_None)) 
                {
                    $result = o;
                }else 
                {
                    if(!PyTuple_Check($result)) 
                    {
                        o2 = $result;
                        $result = PyTuple_New(1);
                        PyTuple_SetItem($result, 0, o2);
                    }
                    
                    o3 = PyTuple_New(1);
                    PyTuple_SetItem(o3,0,o);
                    o2 = $result;
                    $result = PySequence_Concat(o2,o3);
                    Py_DECREF(o2);
                    Py_DECREF(o3);
                }
            }
              
            %typemap(in,numinputs=0) ::google::protobuf::uint32 *OutValue(::google::protobuf::uint32 temp)
            {
                $1 = &temp;
            }
            
            
            %typemap(argout) ::google::protobuf::uint64 *OutValue
            {
                PyObject *o, *o2, *o3;
            
                o = PyLong_FromUnsignedLongLong(*$1);
            
                if((!$result) || ($result == Py_None))
                {
                    $result = o;
                }else
                {
                    if(!PyTuple_Check($result))
                    {
                        o2 = $result;
                        $result = PyTuple_New(1);
                        PyTuple_SetItem($result, 0, o2);
                    }
            
                    o3 = PyTuple_New(1);
                    PyTuple_SetItem(o3, 0, o);
                    o2 = $result;
                    $result = PySequence_Concat(o2, o3);
                    Py_DECREF(o2);
                    Py_DECREF(o3);
                }
            }
            
            %typemap(in,numinputs=0) ::google::protobuf::uint64 *OutValue(::google::protobuf::uint64 temp)
            {
                $1 = &temp;
            }
            
            
            class CodedInputStream 
            {
               public:
                  explicit CodedInputStream(ZeroCopyInputStream* input);
                  explicit CodedInputStream(const ::google::protobuf::uint8* buffer, int size);
                  ~CodedInputStream();
             
                 bool Skip(int count);
                 bool GetDirectBufferPointer(const void** data, int* size);
                 inline void GetDirectBufferPointerInline(const void** data, int* size); 
             
                 bool ReadRaw(void* buffer, int size);
                 bool ReadString(::std::string* buffer, int size);
            
                 bool ReadLittleEndian32(::google::protobuf::uint32 *OutValue);
                 bool ReadLittleEndian64(::google::protobuf::uint64 *OutValue);
             
                 static const ::google::protobuf::uint8* ReadLittleEndian32FromArray(const ::google::protobuf::uint8* buffer, ::google::protobuf::uint32* value);
                 static const ::google::protobuf::uint8* ReadLittleEndian64FromArray(const ::google::protobuf::uint8* buffer, ::google::protobuf::uint64* value);
             
                 bool ReadVarint32(::google::protobuf::uint32* value);
                 bool ReadVarint64(::google::protobuf::uint64* value);
             
                 ::google::protobuf::uint32 ReadTag();
             
                 bool ExpectTag(::google::protobuf::uint32 expected); 
                 static const ::google::protobuf::uint8* ExpectTagFromArray(const ::google::protobuf::uint8* buffer, ::google::protobuf::uint32 expected);
             
                 bool ExpectAtEnd();
                 bool LastTagWas(::google::protobuf::uint32 expected);
                 bool ConsumedEntireMessage();
             
                 typedef int Limit;
             
                 Limit PushLimit(int byte_limit);
                 void PopLimit(Limit limit);
                 int BytesUntilLimit();
             
                 void SetRecursionLimit(int limit);
                 bool IncrementRecursionDepth();
                 void DecrementRecursionDepth();
            };
            
            class CodedOutputStream
            {
               public:
                  explicit CodedOutputStream(ZeroCopyOutputStream* output);
                  ~CodedOutputStream();
            
                  bool Skip(int count);
            
                  bool GetDirectBufferPointer(void** data, int* size);
                  inline ::google::protobuf::uint8* GetDirectBufferForNBytesAndAdvance(int size);
            
                  static ::google::protobuf::uint8* WriteRawToArray(const void* buffer, int size, ::google::protobuf::uint8* target);
                  
                  void WriteString(const ::std::string& str);
                  static ::google::protobuf::uint8* WriteStringToArray(const ::std::string& str, ::google::protobuf::uint8* target);
             
                  void WriteLittleEndian32(::google::protobuf::uint32 value);
                  static ::google::protobuf::uint8* WriteLittleEndian32ToArray(::google::protobuf::uint32 value, ::google::protobuf::uint8* target);
             
                  void WriteLittleEndian64(::google::protobuf::uint64 value);
                  static ::google::protobuf::uint8* WriteLittleEndian64ToArray(::google::protobuf::uint64 value, ::google::protobuf::uint8* target);
            
                  void WriteVarint32(::google::protobuf::uint32 value);
                  static ::google::protobuf::uint8* WriteVarint32ToArray(::google::protobuf::uint32 value, ::google::protobuf::uint8* target);
             
                  void WriteVarint64(::google::protobuf::uint64 value);
                  static ::google::protobuf::uint8* WriteVarint64ToArray(::google::protobuf::uint64 value, ::google::protobuf::uint8* target);
            
                  void WriteVarint32SignExtended(::google::protobuf::int32 value);
                  static ::google::protobuf::uint8* WriteVarint32SignExtendedToArray(::google::protobuf::int32 value, ::google::protobuf::uint8* target);
             
                  void WriteTag(::google::protobuf::uint32 value);
                  static ::google::protobuf::uint8* WriteTagToArray(::google::protobuf::uint32 value,::google::protobuf::uint8* target);
             
                  static int VarintSize32(::google::protobuf::uint32 value);
                  static int VarintSize64(::google::protobuf::uint64 value);
                  static int VarintSize32SignExtended(::google::protobuf::int32 value);
            
                  inline int ByteCount() const;
              
                  bool HadError() const; 
            };
       }
   }
}
